﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using HA.Data;

using System.Windows.Controls;

using System.Windows.Data;



namespace HA.ModFlow.Application
{
   public class ProjectDataViewModel:MDTVIViewModel
    {


       public ProjectDataViewModel(MDTVIViewModel parent)
           : base(parent, false)
       {
          

           this._contextMenu = new System.Windows.Controls.ContextMenu();

           MenuItem mi = new MenuItem();
           mi.Header = "新建";

           this._contextMenu.Items.Add(mi);


           MenuItem miChild;

           //miChild = new MenuItem();
           //miChild.Header = "TIN";
           //miChild.Command = DataCommands.AddTin;

           //mi.Items.Add(miChild);

           //miChild = new MenuItem();
           //miChild.Header = "Borehole";
           //miChild.Command = DataCommands.AddBorehole;

           //mi.Items.Add(miChild);


           //miChild = new MenuItem();
           //miChild.Header = "Grid2D";
           //miChild.Command = DataCommands.AddGrid2D;

           //mi.Items.Add(miChild);



           miChild = new MenuItem();
           miChild.Header = "二维离散点";
           miChild.Command = Data2Commands.AddSactter2D;

           mi.Items.Add(miChild);


           miChild = new MenuItem();
           miChild.Header = "三维网格";
           miChild.Command = DataCommands.AddGrid3D;

           mi.Items.Add(miChild);


           //miChild = new MenuItem();
           //miChild.Header = "三维离散点";
           //miChild.Command = Data2Commands.AddScatter3D;

           //mi.Items.Add(miChild);


          



           miChild = new MenuItem();
           miChild.Header = "概念模型";
           miChild.Command = DataCommands.AddConceptualModel;

           mi.Items.Add(miChild);

           miChild = new MenuItem();
           miChild.Header = "网格边框";
           miChild.Command = DataCommands.AddGridFrame;

           mi.Items.Add(miChild);


           this._imageSource = VMImageSource.Project;

           this.LoadChildren();

       }


       public override string Desc
       {
           get
           {

               string str = "项目" +"("+ ProjectService.DefaultService.GetProjName()+")";
               return str;


           }
       }

       protected override void LoadChildren()
       {
           if (ProjectService.DefaultService.BNullProj)
           {
               return;

           }

           Project project = ProjectService.DefaultService.Project;


           BackImagesViewModel img = new BackImagesViewModel(this, project.AssistData);

           base.Children.Add(img);




           Scatter2dCollectionViewModel scatter2dCollecion = new Scatter2dCollectionViewModel(this,project.Scatter2dData);
           base.Children.Add(scatter2dCollecion);

           Scatter3dCollectionViewModel sd3d = new Scatter3dCollectionViewModel(this,project.Scatter3dData);
           base.Children.Add(sd3d);



           Grid2dCollecionViewModel gcvm = new Grid2dCollecionViewModel(this);
           base.Children.Add(gcvm);








           Grid3dCollecionViewModel vm = new Grid3dCollecionViewModel(this);
           base.Children.Add(vm);


           MapDataViewModel mdvm = new MapDataViewModel(this,project.MapData);

           base.Children.Add(mdvm);








           







           //VtkCollectionViewModel vtkCollection = new VtkCollectionViewModel(this);

           //base.Children.Add(vtkCollection);



           //尝试抽取collectionview

           this._collectionView = (ListCollectionView)CollectionViewSource.GetDefaultView(this.Children);

           _collectionView.Filter = new Predicate<object>(ShowTreeViewItem);
       }


       public Grid3dCollecionViewModel Get3DCollecionVM()
       {
           foreach (MDTVIViewModel item in this.Children)
           {
               if (item is Grid3dCollecionViewModel)
               {
                   return (Grid3dCollecionViewModel)item;
                   
               }
               
           }

           return null;
       }


       private bool ShowTreeViewItem(object item)
       {
           MDTVIViewModel vm = (MDTVIViewModel)item;

           if (vm.Children.Count > 0)
           {
               return true;

           }
           else
           {
               return false;
           }


           //这里由于测试项目的原因，暂时始终返回true
           //return true;

       }


       ListCollectionView _collectionView;

       public ListCollectionView CollectionView
       {
           get { return _collectionView; }
          
       }
       
    }
}
